/*
 * MaterialManager.cpp
 *
 *  Created on: 08.07.2011
 *      Author: alki
 */

#include "MaterialManager.h"

MaterialManager::MaterialManager() {
	this->m_materialien.clear();
}

MaterialManager::~MaterialManager() {
	this->m_materialien.clear();
}

const Material *MaterialManager::getMaterial(unsigned int index) const {
	if(index>=this->m_materialien.size()) {
		throw new Exception(NULL,__FILE__,__LINE__,"index out of bounds","MaterialManager","getMaterial()");
	}

	return &(this->m_materialien[index]);
}

unsigned int MaterialManager::addMaterial(Material m) {
	int n=this->search(m);
	if(n!=-1) {
		return n;
	}

	this->m_materialien.push_back(m);
	return this->m_materialien.size()-1;
}

int MaterialManager::search(Material m) {
	for(unsigned int i=0;i<this->m_materialien.size();i++) {
		if(this->m_materialien[i]==m)
			return i;
	}
	return -1;
}
